package cn.iocoder.yudao.module.brokerage.merchant.controller.admin;

import cn.iocoder.yudao.framework.business.basic.controller.PageController;
import cn.iocoder.yudao.framework.business.basic.controller.SimpleDetailController;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.brokerage.merchant.pojo.vo.AdminBrokerageMerchantBindVO;
import cn.iocoder.yudao.module.brokerage.merchant.pojo.vo.AdminBrokerageMerchantQueryDTO;
import cn.iocoder.yudao.module.brokerage.merchant.pojo.vo.AdminBrokerageMerchantVO;
import cn.iocoder.yudao.module.brokerage.merchant.service.AdminBrokerageMerchantService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 推广商家")
@RestController
@RequestMapping("/brokerage/merchant")
@Validated
public class BrokerageMerchantController implements SimpleDetailController<AdminBrokerageMerchantVO>, PageController<AdminBrokerageMerchantVO, AdminBrokerageMerchantQueryDTO> {
    @Resource
    private AdminBrokerageMerchantService adminBrokerageMerchantService;

    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin')")
    @Override
    public CommonResult<AdminBrokerageMerchantVO> getDetail(Long id) {
        return success(adminBrokerageMerchantService.getDetail(id));
    }

    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin')")
    @Override
    public CommonResult<PageResult<AdminBrokerageMerchantVO>> getPage(Integer pageNo, Integer pageSize, AdminBrokerageMerchantQueryDTO param) {
        return success(adminBrokerageMerchantService.getPage(pageNo, pageSize, param));
    }

    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin')")
    @PostMapping("/bind")
    @Operation(summary = "绑定推广关系")
    public CommonResult<Boolean> bindRelation(@Valid @RequestBody AdminBrokerageMerchantBindVO bindVO) {
        return success(adminBrokerageMerchantService.bindRelation(bindVO.getShopId(), bindVO.getAgencyUserId()));
    }

}